"user strict"
//ie游览器
// var xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
//其他游览器
function success(text) {
    var textarea = document.getElementById('text-from');
    textarea.value = text;
    console.log(text);
}

function fail(code) {
    var textarea = document.getElementById('text-from');
    textarea.value = 'Error code: ' + code;
    console.log(code);
}


var request = new XMLHttpRequest();

request.onreadystatechange = function() {
    if (request.readyState == 4) {
        if (request.status == 200) {
            return success(request.responseText);
        } else {
            return fail(request.status);
        }
    } else {

    }
}
request.open("get", "https://api.openweathermap.org/data/2.5/forecast?q=Beijing,cn&appid=800f49846586c3ba6e7052cfc89af16c");

request.send();






// alert("请求已发送，请等待响应")

//如果无法判断是那种游览器可以两种方法都写

function createXMLHttpRequest() {
    if (window.ActiveXObject) { //判断是否是IE游览器
        xmlHttpRequest = new activeXObject("Microsoft.XMLHTTP"); //是IE游览器创建对象
    } else if (window.xmlHttpRequest) {
        var result = new xmlHttpRequest(); //是其他游览器创建对象
    }
}